home *** CD-ROM | disk | FTP | other *** search
/ Eagles Nest BBS 8 / Eagles_Nest_Mac_Collection_Disc_8.TOAST / Developer Tools⁄Additions / InsideBa1994 / InsideBasic-94 / IB 94 / FN PrintDoc / FN PrintDoc Demo
Text File  |  1992-02-26  |  3KB  |  112 lines

  1.  
  2. DIM OldT1,OldL1,OldB1,OldR1
  3. DIM OldT2,OldL2,OldB2,OldR2
  4. DIM BigT,BigL,BigB,BigR
  5. DIM DestT,DestL,DestB,DestR
  6. DIM ViewT,ViewL,ViewB,ViewR
  7. DIM PT,PL,PB,PR
  8. DIM ZT,ZL,ZB,ZR
  9.  
  10.  
  11. LONG FN PrintDoc(TEHndl&)
  12.   DEF PAGE
  13.   DEF LPRINT
  14.   LONG IF NOT PRCANCEL
  15.                                         ' save original view and dest rects
  16.     BLOCKMOVE PEEK LONG(TEHndl&),VARPTR(OldT1),16
  17.     OldPort& = PEEK LONG(PEEK LONG(TEHndl&)+82)  ' save old port of TE field
  18.     EndLn = PEEK WORD(PEEK LONG(TEHndl&)+94)     ' get total # of lines
  19.     DocHt = FN TEGETHEIGHT(EndLn,1,TEHndl&)+10' get total doc height
  20.     CALL TEDEACTIVATE(TEHndl&)
  21.     BigT = 0 : BigL = 0 : BigB = 8192 : BigR = 8192' a wide open clip rect
  22.     ZT = 0 : ZL = 0 : ZB = 0 : ZR = 0   ' a zero rect
  23.     
  24.     ROUTE 128
  25.     PgSz = WINDOW(7)-2                  ' get height of printer port
  26.     TotalPg = DocHt/PgSz + 1            ' calc number of pages to print
  27.     PgStartLn = 1 : PgEndLn = 1
  28.     CALL GETPORT(PrPort&)
  29.  
  30.                                         ' get port rect
  31.     BLOCKMOVE PrPort& + 16,VARPTR(PT),8
  32.     POKE LONG PEEK LONG(TEHndl&)+82,PrPort&      ' tell TE to output to printer
  33.     BLOCKMOVE VARPTR(PT),VARPTR(DestT),8
  34.     BLOCKMOVE VARPTR(PT),VARPTR(ViewT),8
  35.     DestB = DestT + DocHt
  36.     
  37.     PrecHndl& = PRHANDLE
  38.     FirstPg = PEEK WORD(PEEK LONG(PrecHndl&)+62)
  39.     LastPg = PEEK WORD(PEEK LONG(PrecHndl&)+64)
  40.                                         ' make doc size dest rect
  41.     BLOCKMOVE VARPTR(DestT),PEEK LONG(TEHndl&),8
  42.                                         ' make page size view rect
  43.     BLOCKMOVE VARPTR(ViewT),PEEK LONG(TEHndl&)+8,8
  44.  
  45.     FOR Pg = 1 TO TotalPg
  46.       CALL CLIPRECT(BigT)               ' make wide open clipping rect
  47.       DO
  48.         PgEndLn=PgEndLn+1
  49.         PgHt = FN TEGETHEIGHT(PgEndLn,PgStartLn,TEHndl&)
  50.       UNTIL PgHt > PgSz OR PgEndLn > EndLn
  51.       PgEndLn=PgEndLn-1                 ' last one was too far
  52.       PgHt = FN TEGETHEIGHT(PgEndLn,PgStartLn,TEHndl&)
  53.       PB = PT + PgHt                    ' bottom of update = last whole line
  54.       LONG IF Pg => FirstPg AND Pg <= LastPg
  55.         CALL TEUPDATE(PT,TEHndl&)
  56.         IF Pg<TotalPg THEN CLEAR LPRINT 
  57.       END IF
  58.       CALL CLIPRECT(ZT)                 ' zero rect for clipping
  59.       IF TotalPg > 1 THEN CALL TESCROLL(0,-PgHt,TEHndl&)' scroll pg into view
  60.       PgStartLn = PgEndLn + 1 : PgEndLn = PgStartLn
  61.     NEXT
  62.  
  63.     ROUTE 0
  64.     CLOSE LPRINT
  65.                                         ' restore view & dest rects
  66.     BLOCKMOVE VARPTR(OldT1),PEEK LONG(TEHndl&),16
  67.     POKE LONG PEEK LONG(TEHndl&)+82,OldPort&     ' restore original port, too
  68.     CALL TEACTIVATE(TEHndl&)
  69.   END IF
  70. END FN
  71.  
  72.  
  73. COORDINATE WINDOW:WIDTH-2
  74.  
  75. MENU 1,0,1,"File"
  76. MENU 1,1,1,"Print"
  77. MENU 1,2,1,"Quit"
  78.  
  79. ON MENU GOSUB "Menu"
  80. ON BREAK GOSUB "Break"
  81. ON DIALOG GOSUB "Dialog"
  82.  
  83. WINDOW #1,"Edit Field Print Test",(40,40)-(490,310),1
  84. EDIT FIELD 1,"This is an edit field.",(4,4)-(432,250),2
  85. CALL TEAUTOVIEW(-1,TEHANDLE(1))
  86.  
  87. "Loop"
  88. MENU ON:BREAK ON : DIALOG ON
  89. MENU OFF:BREAK OFF : DIALOG OFF
  90. GOTO "Loop"
  91.  
  92. "Menu"
  93. MenuID = MENU(0):ItemID = MENU(1)
  94.  
  95. ON ItemID GOTO "Print","Quit"
  96.  
  97. "Dialog"
  98. Act = DIALOG(0):Ref = DIALOG(Act)
  99. RETURN
  100.  
  101.  
  102. "Print"
  103. TEHndl& = TEHANDLE(1)
  104. FN PrintDoc(TEHndl&)
  105. MENU
  106. RETURN
  107.  
  108. "Quit"
  109. "Break"
  110. END
  111.  
  112.